package com.salinity.kun.task;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.salinity.kun.helper.BaseHydrologyDataHelper;
import com.salinity.kun.helper.ConstantHelper;
import com.salinity.kun.model.StationDateData;

public class OneMonthLvHuaShanDenseInterpolationTask implements ITask {
	// Path inputPath =
	// Paths.get("E:\\Kuner\\研究生\\论文相关\\data\\绿华山\\LvhuaShan_1.csv");
	// Path outputPath = Paths.get("E:\\Kuner\\研究生\\论文相关\\data\\绿华山\\");

	Path inputPath = Paths.get("E:\\Kuner\\研究生\\论文相关\\data\\潮位数据\\绿华山.csv");
	Path outputPath = Paths.get("E:\\Kuner\\研究生\\论文相关\\data\\潮位数据\\");

	@Override
	public boolean run() throws IOException, ParseException {

		int rawDeltaT = 60;
		int hours = 6 * 24;
		// List<StationDateData> tideList =
		// BaseHydrologyDataHelper.getTidesFromFile(inputPath, rawDeltaT, hours);
		SimpleDateFormat sdf = ConstantHelper.getDateFormat();
		Date sDate = sdf.parse("2018/7/1  0:00:00");
		List<StationDateData> tideList = BaseHydrologyDataHelper.getTidesFromFile(inputPath, sDate, rawDeltaT, hours, 0,
				0, 1, 100);
		List<StationDateData> tideList_new = BaseHydrologyDataHelper.getDataByInterval(tideList, sDate, rawDeltaT);
		List<StationDateData> denseTideList = BaseHydrologyDataHelper.doProportionalInterpolation(tideList_new,
				rawDeltaT, 12, false);

		BaseHydrologyDataHelper.writeToFile(denseTideList, outputPath.resolve("LvHuaShan_7_5min_old.csv"));
		denseTideList = BaseHydrologyDataHelper.doProportionalInterpolation(tideList_new, rawDeltaT, 12, true);

		BaseHydrologyDataHelper.writeToFile(denseTideList, outputPath.resolve("LvHuaShan_7_5min_new.csv"));
		denseTideList = BaseHydrologyDataHelper.doLinearInterpolation(tideList, sDate, sdf.parse(tideList.get(tideList.size()-1).getDate()), 5);
		BaseHydrologyDataHelper.writeToFile(denseTideList, outputPath.resolve("LvHuaShan_7_5min_new_linear.csv"));
		
		System.out.println("complete.");
		return true;
	}

	public static void main(String[] args) {
		ITask task = new OneMonthLvHuaShanDenseInterpolationTask();

		try {
			task.run();
		} catch (IOException | ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
